const white_list = [
    '/',
    '/singin',
    '/user/signin',
    '/registered',
    '/Details',
    '/forget',
    '/announcement',
    '/m',
    '/m/singin',
    '/m/registered',
    '/m/forget',
    '/m/announcement',
    '/m/Details',
    '/lottery/getResult'
];

module.exports =  async (ctx, next) => {
    let defualt_url='/'
    let useragent=ctx.headers['user-agent'].toLowerCase()
    let ismobile = /(iphone|ipod|ipad|android)/.test(useragent)
    if(!ismobile){
        defualt_url='/m'
    }
    if(ctx.method == 'POST'){
        await next();
    }
    else{
        if(white_list.includes(ctx.originalUrl) != -1){
            await next();
        }
        else{
            if(ctx.session == undefined || ctx.session.userId == undefined){
                ctx.redirect(defualt_url);
            }
            else{
                await next();
            }
        }
    }
}